777A - Shell Game - CodeForces Solution


constructive algorithms implementation math *1000

Please click on ads to support us..

Python Code:

n=int(input())
p=int(input())
ls1=[0,1,2]
ls2=[1,0,2]
if(n%6==0):
    print(ls1[p])
elif(n%6==1):
    print(ls2[p])
elif(n%6==2):
    ls1=ls1[1:]+ls1[:1]
    print(ls1[p])
elif(n%6==3):
    ls2=ls2[-1:]+ls2[:-1]
    print(ls2[p])
elif(n%6==4):
    ls1=ls1[2:]+ls1[:2]
    print(ls1[p])
elif(n%6==5):
    ls2=ls2[-2:]+ls2[:-2]
    print(ls2[p])

C++ Code:

// #include <bits/stdc++.h>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <istream>
#include <numeric>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long ll;
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
#define gogo ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define assertm(exp, msg) assert(((void)msg, exp))
#define rep(i, a, n) for (int i = a;i < n;i ++)
#define per(i, n, a) for (int i = n - 1;i>= a;i --)
#define x first
#define y second
#define vt vector
#define ar array
#define pb push_back
#define sz(x) (int)(x).size()
#define EACH(x, a) for (auto& x: a)
#define FOR(a) for(auto it : a)
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
template<class A> void read(vector<A>& v);
template<class A, size_t S> void read(array<A, S>& a);
template<class T> void read(T& x) {cin >> x;}
void read(double& d) {string t;read(t);d=stod(t);}
void read(long double& d) {string t;read(t);d=stold(t);}
template<class H, class... T> void read(H& h, T&... t) {read(h);read(t...);}
template<class A> void read(vt<A>& x) { EACH(a, x) read(a); }
template<class A, size_t S> void read(array<A, S>& x) { EACH(a, x) read(a);}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
template<class A> void write(A x) { cout << x; }
template<class H, class... T> void write(const H& h, const T&... t) { write(h);write(t...); }
void print() { write("\n"); }
template<class H, class... T> void print(const H& h, const T&... t) { 
    write(h);
    if(sizeof...(t))
        write(' ');
    print(t...);
}
template <typename T> void outg(vector<vector<T>> &v) {
    if(empty(v)) return;
    int n = v.size(), m = v[0].size();
    vector<vector<T>> res(m, vector<T>(n));
    rep(i, 0, n) {
        rep(j, 0, m) 
            write(v[i][j], ' ');
        print();
    }
}
template <typename T> void outv(vector<T> &v) {
    if(empty(v)) return;
    for (auto i : v) write(i, ' ');
    print();
}
template<typename T_vector>
void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());
    for (int i = start;i < end;i ++)
        cout << v[i] << (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
template <class T, class S> T POW(T x, S n, const ll &mod) {
    T res = 1;
    x %= mod;
    for(; n; n >>= 1, x = x * x % mod)
        if(n & 1) res = res * x % mod;
    return res;
}
template <class T> T POW(T x, int n) {
    T res = 1;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
template <typename T> void rot(vector<vector<T>> &v) {
    if(empty(v)) return;
    int n = v.size(), m = v[0].size();
    vector<vector<T>> res(m, vector<T>(n));
    rep(i, 0, n) rep(j, 0, m) res[m - 1 - j][i] = v[i][j];
    v.swap(res);
}
// x in [l, r)
template <class T, class S> bool inc(const T &x, const S &l, const S &r) { return l <= x and x < r; }
string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }
string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }
namespace DEBUG {
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& V) {
  os << "[ ";
  for (const auto& vv : V) os << vv << ", ";
  os << "]";
  return os;
}
template <typename T>
inline void _debug(const char* format, T t) {
  cerr << format << '=' << t << endl;
}
template <class First, class... Rest>
inline void _debug(const char* format, First first, Rest... rest) {
  while (*format != ',') cerr << *format++;
  cerr << '=' << first << ",";
  _debug(format + 1, rest...);
}
#define debug(...) _debug(#__VA_ARGS__, __VA_ARGS__)
}  // namespace DEBUG

using namespace DEBUG;
int main() {
	gogo;

	int N, x;
	cin >> N >> x;

	int ans[6][3] = {
		{1, 0, 2},
		{1, 2, 0},
		{2, 1, 0},
		{2, 0, 1},
		{0, 2, 1},
		{0, 1, 2}
	};

	cout << ans[(N - 1) % 6][x] << '\n';

    return 0;
}






Comments

Submit
0 Comments
More Questions

1516A - Tit for Tat
622. Design Circular Queue
814. Binary Tree Pruning
791. Custom Sort String
787. Cheapest Flights Within K Stops
779. K-th Symbol in Grammar
701. Insert into a Binary Search Tree
429. N-ary Tree Level Order Traversal
739. Daily Temperatures
647. Palindromic Substrings
583. Delete Operation for Two Strings
518. Coin Change 2
516. Longest Palindromic Subsequence
468. Validate IP Address
450. Delete Node in a BST
445. Add Two Numbers II
442. Find All Duplicates in an Array
437. Path Sum III
436. Find Right Interval
435. Non-overlapping Intervals
406. Queue Reconstruction by Height
380. Insert Delete GetRandom O(1)
332. Reconstruct Itinerary
368. Largest Divisible Subset
377. Combination Sum IV
322. Coin Change
307. Range Sum Query - Mutable
287. Find the Duplicate Number
279. Perfect Squares
275. H-Index II